from twisted.protocols import amp
import math

##
##  Server -> Client Commands
##
class Kick(amp.Command):
    arguments      = [('reason',amp.String())]
    response       = []
    requiresAnswer = False

class AddSession(amp.Command):
    arguments      = [('id',amp.Integer()),('lobby_state',amp.Integer())]
    response       = []
    requiresAnswer = False

class RemoveSession(amp.Command):
    arguments      = [('id',amp.Integer())]
    response       = []
    requiresAnswer = False

class ChangeProgramState(amp.Command):
    arguments      = [('program_state',amp.Integer())]
    response       = []
    requiresAnswer = False

class AddSnakePart(amp.Command):
    arguments      = [('id',amp.Integer()),('row',amp.Integer()),('col',amp.Integer())]
    response       = []
    requiresAnswer = False

class PlaceFood(amp.Command):
    arguments      = [('row',amp.Integer()),('col',amp.Integer())]
    response       = []
    requiresAnswer = False

class Tick(amp.Command):
    arguments      = [('id',amp.Integer()),('row',amp.Integer()),('col',amp.Integer())]
    response       = []
    requiresAnswer = False

##
## Client -> Server commands
##
class Handshake(amp.Command):
    arguments      = []
    response       = [('session_id',amp.Integer())]

##
## Client <-> Server commands
##
class SetHeading(amp.Command):
    arguments      = [('id',amp.Integer()),('new_heading',amp.Integer())]
    response       = []
    requiresAnswer = False

class LobbyStateChange(amp.Command):
    arguments      = [('id',amp.Integer()),('lobby_state',amp.Integer())]
    response       = []
    requiresAnswer = False

TILE_SIZE       = 16   ## pixels per tile
H_TILES         = 24   ## how may horizontal tiles
V_TILES         = 14   ## how many vertical tiles

class LobbyState:
    WAITING     = 0
    NOT_READY   = 1
    READY       = 2

class ProgramState:
    EXITING   = 0
    CONECTING = 1
    LOBBY     = 2
    GAME      = 3

class Heading:
    UP    = 0
    RIGHT = 1
    DOWN  = 2
    LEFT  = 3
    VALID_HEADINGS = [0,1,2,3]
